package com.alibaba.travel.member.test;


import com.alibaba.travel.member.entity.UserEntity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Date;

@SpringBootTest
public class testapplication {
    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    void name() throws JsonProcessingException {
        UserEntity userEntity = new UserEntity();
        userEntity.setId(1l);
        userEntity.setUserName("usernmae");
        userEntity.setPassword("password");
        userEntity.setUpdateTime(new Date());
        userEntity.setCreateTime(new Date());
        String json = objectMapper.writeValueAsString(userEntity);
        System.out.println("json="+json);
        stringRedisTemplate.opsForValue().set("json",json);
        String json1 = stringRedisTemplate.opsForValue().get("json");
        UserEntity userEntity1 = null;
        try {
            userEntity1 = objectMapper.readValue(json1, userEntity.getClass());
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println("userEntity="+userEntity1.toString());


    }



}
